unit AfterDownload_TestForm;

interface

uses
  RegExpr,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TAD_TestForm = class(TForm)
    Label1: TLabel;
    CBX_Files: TComboBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    BitBtn1: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure CBX_FilesChange(Sender: TObject);
  private
    { Private declarations }
    FFiles: TStrings;
    FExpr: String;
    RE: TRegExpr;
    procedure SetLanguage(language: String);
    procedure TranslateToo;
    procedure SetFiles(NewFiles: TStrings);
    procedure SetExpr(const NewExpr: String);
  public
    { Public declarations }
    property Language: String write SetLanguage;
    property Files: TStrings read FFiles write SetFiles;
    property Expr: String read FExpr write SetExpr;
  end;

var
  AD_TF: TAD_TestForm = nil;

implementation

{$R *.dfm}

uses
  gnugettext,
  Locales,
  AfterDownload_Defines;

procedure TAD_TestForm.SetLanguage(language: String);
begin
 TranslateForm(Self, Language, TranslateToo);
end;

procedure TAD_TestForm.TranslateToo;
begin
 BitBtn1.Caption:=_('Close');
end;

procedure TAD_TestForm.SetFiles(NewFiles: TStrings);
begin
 FFiles.Clear;
 if Assigned(NewFiles) then
   FFIles.AddStrings(NewFiles);
 //
 CBX_Files.Items.Clear;
 CBX_Files.Items.AddStrings(FFiles);
 if CBX_Files.Items.Count>0 then
  begin
   CBX_Files.ItemIndex:=0;
   CBX_FilesChange(nil);
  end;
end;

procedure TAD_TestForm.FormCreate(Sender: TObject);
begin
 TranslateComponent(Self);
 //
 FExpr:='';
 RE:=TRegExpr.Create;
 RE.ModifierI:=true; //case insensitive search
 Label5.Caption:='';
 FFiles:=TStringList.Create;
end;

procedure TAD_TestForm.FormDestroy(Sender: TObject);
begin
 FreeAndNil(RE);
 FreeAndNil(FFiles);
end;

procedure TAD_TestForm.SetExpr(const NewExpr: String);
begin
 RE.Expression:=NewExpr;
 Label3.Caption:=NewExpr;
end;

procedure TAD_TestForm.CBX_FilesChange(Sender: TObject);
 var
   s: String;
begin
 if CBX_Files.ItemIndex<0 then Exit;
 s:=CBX_Files.Items[CBX_Files.ItemIndex];
 if RE.Exec(s) then
   Label5.Caption:=RE.Match[0]
 else
  begin
   if IsValidFilename(ExtractFilename(s)) then
     Label5.Caption:=RE.Expression
   else
     Label5.Caption:=_('File name does not fit.');
  end;
end;

end.
